<script setup>
import CesiumMapDemo from '../components/CesiumMapDemo.vue'
import CoordinateTransformDemo from '../components/CoordinateTransformDemo.vue'
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 当前显示的组件
const currentComponent = ref('map') // 'map' 或 'coordinate'

// 切换组件
const switchComponent = (component) => {
  currentComponent.value = component
}

// 导航到高级功能页面
const goToAdvanced = () => {
  router.push('/advanced-cesium')
}

// 导航到简单演示页面
const goToSimple = () => {
  router.push('/simple-cesium')
}

// 导航到坐标转换页面
const goToCoordinateTransform = () => {
  router.push('/coordinate-transform')
}
</script>

<template>
  <main>
    <!-- 导航菜单 -->
    <div class="nav-menu">
      <div class="nav-container">
        <div class="nav-links">
          <button 
            @click="switchComponent('map')" 
            :class="['nav-btn', { active: currentComponent === 'map' }]"
          >
            基础地图演示
          </button>
          <button 
            @click="switchComponent('coordinate')" 
            :class="['nav-btn', { active: currentComponent === 'coordinate' }]"
          >
            坐标系转换工具
          </button>
          <button 
            @click="goToAdvanced" 
            class="nav-btn advanced-btn"
          >
            高级功能演示
          </button>
          <button 
            @click="goToSimple" 
            class="nav-btn"
          >
            简单演示
          </button>
          <button 
            @click="goToCoordinateTransform" 
            class="nav-btn"
          >
            完整坐标转换
          </button>
        </div>
      </div>
    </div>
    
    <!-- 组件内容 -->
    <div class="content-section">
      <CesiumMapDemo v-if="currentComponent === 'map'" />
      <CoordinateTransformDemo v-if="currentComponent === 'coordinate'" />
    </div>
  </main>
</template>

<style scoped>
main {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.nav-menu {
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  z-index: 1000;
  flex-shrink: 0; /* 防止导航栏被压缩 */
}

.nav-container {
  display: flex;
  justify-content: center; /* 居中显示按钮 */
  align-items: center;
  padding: 0 20px;
  height: 60px;
}

.nav-title {
  margin: 0;
  color: #333;
  font-size: 24px;
  font-weight: bold;
}

.nav-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.nav-btn {
  padding: 10px 20px;
  background: #f8f9fa;
  color: #495057;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  min-width: 120px; /* 确保按钮有最小宽度 */
  white-space: nowrap;
}

.nav-btn:hover {
  background: #e9ecef;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.nav-btn.active {
  background: #409eff;
  color: white;
  border-color: #409eff;
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
}

.nav-btn.advanced-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: #667eea;
}

.nav-btn.advanced-btn:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.content-section {
  flex: 1;
  overflow: hidden;
  position: relative; /* 确保内容区域正确定位 */
}
</style>
